Skip to content

ContextHelper::is_in_isset_or_empty(): add basic tests#2725

Merged
jrfnl merged 3 commits intodevelopfrom
is-in-isset-or-empty-tests
Apr 27, 2026
Merged

ContextHelper::is_in_isset_or_empty(): add basic tests#2725
jrfnl merged 3 commits intodevelopfrom
is-in-isset-or-empty-tests

Conversation

@rodrigoprimo
Copy link
Copy Markdown
Collaborator

Description

In preparation for supporting PHPCS 4.0, this PR adds unit tests for the ContextHelper::is_in_isset_or_empty() method.

Suggested changelog entry

N/A

$obj?->key_exists( 'key', /* testNullsafeObjectMethod */ $array );
MyClass::array_key_exists( 'key', /* testStaticMethod */ $array );
key_exists( 'key', my_function( /* testNestedFunctionCall */ $array ) );

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about the negative test of just bare $value too?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review, @GaryJones. I added the bare $value negative test you suggested. I also added a nested valid function call test similar to the one you suggested in the review of #2721 and renamed testNestedFunctionCall to testNestedNonTargetFunctionCall to better contrast with the new positive case.

$obj?->key_exists( 'key', /* testNullsafeObjectMethod */ $array );
MyClass::array_key_exists( 'key', /* testStaticMethod */ $array );
key_exists( 'key', my_function( /* testNestedNonTargetFunctionCall */ $array ) );

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about adding these ("no false positives") tests too ?

Foo::isset();
Some\Ns\empty();

And maybe one or two variations, don't need to be silly comprehensive as the tokenizer wouldn't tokenize the above as T_ISSET/T_EMPTY (which is why this isn't specifically tested in PHPCSUtils and all the more reason we should have a few of these tests here).

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about it, but then opted not to add the tests precisely because PHPCS doesn't tokenize the above as T_ISSET/T_EMPTY. That said, those tests will not hurt, and I added a new commit with them.

Copy link
Copy Markdown
Member

@jrfnl jrfnl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @rodrigoprimo, LGTM!

@jrfnl jrfnl added this to the 3.4.0 milestone Apr 27, 2026
@jrfnl jrfnl merged commit 16a785e into develop Apr 27, 2026
42 checks passed
@jrfnl jrfnl deleted the is-in-isset-or-empty-tests branch April 27, 2026 12:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants